﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Nova_DAL;
using Nova_Common;
using System.Data.Common;
using Nova_MOD;
using Nova_BLL;
using Nova_Common.Extend;
using System.Collections.Generic;

public partial class Stock_BookList : System.Web.UI.Page
{
    DbHelper access = new DbHelper();
    DbHelper dbHelper = new DbHelper();
    DbCommand cmd = null;
    DataSet ds = null;
    string strSQL = "";
    int i = 0;

    TMaterialGroupInfoBll MaterialGroupBll = new TMaterialGroupInfoBll();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            gvbind();

        }
    }

    protected string getSQL()
    {
        strSQL = @"select TBM.Mat_Code,TBM.Mat_Name,TBM.S01,TBM.TM01,TBM.TM03,S02,TBM.Unit_Base
            FROM dbo.TBase_Material TBM WHERE 1=1 ";
        if (txtMat_Name.Text.Trim() != "")
        {
            strSQL += " and TBM.Mat_Name like '%" + txtMat_Name.Text.Trim() + "%'";
        }
        if (txtS01.Text.Trim() != "")
        {
            strSQL += " and TBM.S01 like '%" + txtS01.Text.ToString().Trim() + "%'";
        }
        strSQL += " ORDER BY TBM.CDT DESC";
        return strSQL;
    }

    protected void gvbind()
    {
        try
        {
            cmd = access.GetSqlStringCommond(getSQL());
            gv.DataSource = access.ExecuteDataSet(cmd);
            gv.DataBind();
        }
        catch (Exception ex)
        {

        }
    }

    protected void ibtnSearch_Click(object sender, ImageClickEventArgs e)
    {
        //ddMaterialType();
        gvbind();
    }

    protected void gv_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        gv.PageIndex = e.NewPageIndex;
        gvbind();  //重新绑定GridView
    }
    protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label LabMat_Code = (Label)e.Row.Cells[1].FindControl("LabMat_Code");
            // e.Row.Attributes.Add("onclick", "parent.window.returnValue='" + e.Row.Cells[1].Text.Trim().Replace("&nbsp;", "") + "," + LabMat_Code.Text.Trim() + "," + e.Row.Cells[3].Text.Trim().Replace("&nbsp;", "") + "," + e.Row.Cells[4].Text.Trim().Replace("&nbsp;", "") + "';parent.window.close();");

            e.Row.Attributes.Add("onclick", "window.parent.opener.document.getElementById('txt_Mat_Code').value='" + LabMat_Code.Text.ToString() + "';window.parent.opener.document.getElementById('txt_Mat_Name').value='" + e.Row.Cells[1].Text.Trim().Replace("&nbsp;", "") + "';window.parent.opener.document.getElementById('txt_S01').value='" + HttpUtility.HtmlDecode(e.Row.Cells[3].Text.Trim().Replace("&nbsp;", "")) + "';window.parent.opener.document.getElementById('txt_TM01').value='" + e.Row.Cells[4].Text.Trim().Replace("&nbsp;", "") + "';window.parent.opener.document.getElementById('txt_TM03').value='" + e.Row.Cells[5].Text.Trim().Replace("&nbsp;", "") + "';window.parent.opener.document.getElementById('txt_S02').value='" + e.Row.Cells[6].Text.Trim().Replace("&nbsp;", "").Replace("\r\n","") + "';parent.window.close();");

            //鼠标移动到每项时颜色交替效果   
            e.Row.Attributes.Add("OnMouseOut", "this.style.backgroundColor='White';this.style.color='#003399'");
            e.Row.Attributes.Add("OnMouseOver", "this.style.backgroundColor='#6699FF';this.style.color='#8C4510'");

            //设置悬浮鼠标指针形状为"小手"   
            e.Row.Attributes["style"] = "Cursor:hand";
        }
    }
}